﻿#include<stdio.h>
#include<iostream>
#include <map>
#include <queue>
#include <vector>
#include<algorithm>
#include<string>
using namespace std;
bool cmp(string s1, string s2) {
	if (s1.compare(s2) < 0)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
void sort(vector<string>& q1)
{
	int i, j;
	string s1;
	sort(q1.begin(), q1.end(), cmp);

}

int main()
{
	ios::sync_with_stdio(false);

	int x;
	int y;
	int z;
	map<int, vector<string>> person;
	char c;
	int num;
	int i, j, k;
	string s;
	vector<string> q1;
	cin >> x >> y;
	for (j = 1; j <= y; j++)
	{
		person.insert(pair<int, vector<string>>(j, q1));
	}
	for (j = 0; j < x; j++)
	{
		cin >> s;
		cin >> num;
		for (i = 0; i < num; i++)
		{
			cin >> k;

			person[k].push_back(s);

			//将此学生选的num们课添加进去
		}

	}


	for (j = 1; j <= y; j++)
	{
		cout << j << " " << person[j].size() << endl;
		sort(person[j]);
		for (i = 0; i < person[j].size(); i++)
		{
			cout << person[j][i] << endl;
		}

	}

}
